//
//  MVCController.m
//  PrintJob
//
//  Created by blank on 2017/5/8.
//  Copyright (c) 2017 CYN. All rights reserved.
//

#import "MVCController.h"
#import "MVCView.h"
#import "Paper.h"

@interface MVCController () <MVCViewDelegate>

@property(nonatomic, strong) MVCView *mvcView;

@property(nonatomic, strong) Paper *paper;

@end

@implementation MVCController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor grayColor]];
    [self printPaper];
}

- (MVCView *)mvcView {
    if (!_mvcView) {
        _mvcView = [[MVCView alloc] init];
        [_mvcView setDelegate:self];
        [_mvcView setFrame:self.view.bounds];
        [self.view addSubview:_mvcView];
    }
    return _mvcView;
}

- (Paper *)paper {
    if (!_paper) {
        _paper = [[Paper alloc] init];
        [_paper setContent:@"line 0"];
    }
    return _paper;
}


- (void)printPaper {
    [self.mvcView printOnView:self.paper];
}

- (void)onPrintBtnClick {
    [self.paper setContent:[NSString stringWithFormat:@"line %u", arc4random() % 10]];

    [self printPaper];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
